<?php
require_once("../includes/config.php");
include DIR_INCLUDES_FT.'bootstrap.php';

switch ($_POST['accao']){
	case 'verifica_categoria':
		$num_rep = Doctrine_Query::create()->from("Categorias c")
			->where("c.nome = ? and c.id != ?", array($_POST['nome'],$_POST['id']))->count();
		if($num_rep > 0){
			echo json_encode(false);
		} else {
			echo json_encode(true);
		}
	break;
	case 'verifica_produto':
		$num_rep = Doctrine_Query::create()->from("Produtos p")
					->where("p.nome = ? and p.categoria_id = ? and p.id != ?", array($_POST['nome'],$_POST['categoria'], $_POST['id']))->count();
		if($num_rep > 0){
			echo json_encode(false);
		} else {
			echo json_encode(true);
		}
	break;
}

?>